//
//  CZHomeBottomView.swift
//  CZVVeiBo
//
//  Created by smile on 2017/8/3.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

class CZHomeBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = RGB(red: 235, green: 235, blue: 235)
        
        let retweetButton = addChildButtons(imgName: "timeline_icon_retweet", title: "转发")
        let commentButton = addChildButtons(imgName: "timeline_icon_comment", title: "评论")
        let unlikeButton = addChildButtons(imgName: "timeline_icon_unlike", title: "赞")
        
        let line1 = addChildLines()
        let line2 = addChildLines()
        
        retweetButton.snp.makeConstraints { (make) in
            make.top.left.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.left.equalTo(retweetButton.snp.right)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp.makeConstraints { (make) in
            make.top.bottom.right.equalTo(self)
            make.left.equalTo(commentButton.snp.right)
        }
        
        line1.snp.makeConstraints({ (make) in
            make.centerX.equalTo(retweetButton.snp.right)
            make.centerY.equalTo(self)
        })
        
        line2.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(unlikeButton.snp.left)
        }
        
    }
    
    /// 创建按钮的公共方法
    ///
    /// - Parameters:
    ///   - imgName: 图片名字
    ///   - title: 文字
    fileprivate func addChildButtons(imgName: String, title: String) -> UIButton{
        let button = UIButton()
        // 背景图片
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), for: UIControlState.normal)
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background_highlighted"), for: UIControlState.highlighted)
        // 图片
        button.setImage(UIImage(named: imgName), for: UIControlState.normal)
        // 文字
        button.setTitle(title, for: UIControlState.normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        button.setTitleColor(CZAPPThemeColor, for: UIControlState.highlighted)
        // 添加按钮
        addSubview(button)
        return button
    }
    // 创建竖线的公共方法
    fileprivate func addChildLines() -> UIImageView{
        let img = UIImageView(imgName: "timeline_card_bottom_line")
        addSubview(img)
        return img
    }
}




